// 1.递归
function fibonacci(n) {
  if (n == 1 || n == 2) {
      return 1
  };
  return fibonacci(n - 2) + fibonacci(n - 1);
}
fibonacci(30)

//2.闭包
var fibonacci = function () {
  let memo = [0, 1];
  let fib = function (n) {
      if (memo[n] == undefined) {
          memo[n] = fib(n - 2) + fib(n - 1)
      }
      return memo[n]
  }
  return fib;
}()
fibonacci(30)

//3.普通for循环
var fibonacci = function (n) {
  let n1 = 1; n2 = 1;
  for (let i = 2; i < n; i++) {
      [n1, n2] = [n2, n1 + n2]
  }
  return n2
}
fibonacci(30)
